<template>
    <div>
        <el-row>
            <el-col :span="4"><el-button type="primary" plain @click="showAddPatient">添加患者</el-button></el-col>
            <el-col :span="6"><el-input v-model="input" placeholder="姓名" prefix-icon="el-icon-search"></el-input></el-col>
            <el-col :span="4"><el-button type="primary" plain>查询</el-button></el-col>
        </el-row>
            <el-table :data="tableData" border style="width: 98%">
            <el-table-column prop="name" label="姓名" width="180" > </el-table-column>
            <el-table-column prop="idcard" label="身份证号" width="180" align="center"></el-table-column>
            <el-table-column prop="gender" label="性别" width="60" align="center"> </el-table-column>
            <el-table-column  prop="address" label="地址"></el-table-column>
            <el-table-column  label="住院日期" width="120" align="center">
                <!-- 当表格列的内容还要显示其他效果时，就需要自定义模板  slot-scope="scope"作用域插槽 -->
                <template slot-scope="scope">  
                    <i class="el-icon-time"></i>
                    <span style="margin-left: 10px">{{ scope.row.date }}</span>
                    <!-- .row固定写法，表示当前行 -->
                </template>
            </el-table-column>
            <el-table-column prop="origin" label="感染来源" width="280"> </el-table-column>
            <el-table-column label="操作" width="280" align="center"> 
                <el-button plain size="mini" @click="showById">编辑</el-button>
                <el-button type="primary" plain size="mini" @click="showById2">检测记录</el-button>
                <el-button type="primary" plain size="mini" @click="showCureDialog">治愈</el-button>
            </el-table-column>
        </el-table>
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage4"
            :page-sizes="[1, 2, 3, 4]"
            :page-size="3"
            layout="total, sizes, prev, pager, next, jumper"
            :total="3">
        </el-pagination>
        <el-dialog title="治愈" :visible.sync="dialogFormVisible">
            <el-form :model="form">
                <el-form-item label="治愈时间"><br>
                    <el-date-picker
                        v-model="value1"
                        type="date"
                        placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="备注"><br>
                    <el-input type="textarea" v-model="form.desc" rows="4"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
            </div>
        </el-dialog>
    </div>
    
</template>
<script>
import request from '@/utils/request'
export default {
  data() {
    return {
        input: '',
        tableData:null,
        currentPage4: 1,
        value1: '',
        dialogFormVisible: false,
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
        },
        formLabelWidth: '120px'
    }
  },
  created(){
      this.fetchData()
  },
  methods:{
    fetchData() {
        request({
            url: '../patient_list.json',
            method: 'get',
        }).then(response =>{
            this.tableData = response.data
        })
    },
    handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
    },
    showById(){
      this.$router.push("/patient/modify")
    },
    showById2(){
      this.$router.push("/patient/addtestrecord")
    },
    showCureDialog(){
        this.dialogFormVisible = true
    },
    showAddPatient(){
        this.$router.push("/patient/PatientAddpatient")
    }
  },
}
</script>